import com.google.gson.Gson;

import fi.laurea.jsonbus.Receiver;
import fi.laurea.jsonbus.ReceiverListener;

public class DemoListener implements ReceiverListener {

	private Receiver receiver;
	private Gson gson;
	private String name;

	public DemoListener(String channel, String name) {
		this.receiver = new Receiver(channel, name, this);
		this.gson = new Gson();
		this.name = name;
	}

	@Override
	public void prosessGloballMessage(String json) {
		DemoMessage message = (DemoMessage) gson.fromJson(json,
				DemoMessage.class);
		System.out.println(this.name + " received global message '"
				+ message.getText() + "'");
	}

	@Override
	public void prosessPrivateMessage(String json) {
		DemoMessage message = (DemoMessage) gson.fromJson(json,
				DemoMessage.class);
		System.out.println(this.name + " received private message '"
				+ message.getText() + "'");
	}

}
